package com.excilys.patricksbank.model;

import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Immutable;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;

@Entity
@Table(name = "operation")
public class Operation {

	public enum TypeOperation {
		RETRAIT, VIREMENT_EMIS, VIREMENT_RECU, PAIEMENT_CARTE, CHEQUE, REMISE_CHEQUE,
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "idOperation", unique = true, nullable = false)
	private String idOperation;
	private double montant;
	private String detail;
	@Column(name = "dateOperation")
	@Type(type="org.jadira.usertype.dateandtime.joda.PersistentDateTime")
	private DateTime date;
	private TypeOperation typeOperation;

	@ManyToOne(cascade = CascadeType.ALL, targetEntity = Compte.class)
	@JoinColumn(name = "idCompte")
	private Compte compte;

	public String getIdOperation() {
		return idOperation;
	}

	public void setIdOperation(String idOperation) {
		this.idOperation = idOperation;
	}

	public double getMontant() {
		return montant;
	}

	public void setMontant(double montant) {
		this.montant = montant;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public DateTime getDate() {
		return date;
	}

	public void setDate(DateTime date) {
		this.date = date;
	}

	public TypeOperation getTypeOperation() {
		return typeOperation;
	}

	public void setTypeOperation(TypeOperation typeOperation) {
		this.typeOperation = typeOperation;
	}

	public Compte getCompte() {
		return compte;
	}

	public void setCompte(Compte compte) {
		this.compte = compte;
	}

	public String getDateFormatee() {
		return date.toString("dd/MM/yyyy");
	}



}
